<!--
 * @Description:支付方式
-->

<template>
  <div class="registered-container payWaySetup appMainWarp">
    <!-- <el-form :inline="true" class="demo-form-inline">
      <div class="title-top"><span></span>跑批退费规则</div>
      <el-form-item label="退费时间:">
        <div style="display:flex;">
          <div v-for="(item,index) in refundTime" :key="index" class="parent-position">
            <el-time-picker v-model="item.timeVal" placeholder="选择时间" value-format="HH:mm" format="HH:mm" style="width:183px" />
            <i style="color:#fe6b3d;" class="el-icon-circle-close time-close" @click="delTime(index)" />
          </div>
          <el-button
            type="primary"
            icon="el-icon-plus"
            style="border-color: #fff;"
            @click="addTime()"
          />
        </div>
      </el-form-item>
    </el-form> -->
    <!-- <el-form :inline="true" class="demo-form-inline" style="display:flex;">
      <el-form-item label="退费规则:" style="display:flex;">
        <div v-for="(item,index) in refundRule" :key="index" style="display:flex;">
          <el-select v-model="item.refundType" placeholder="请选择退费业务类型">
            <el-option
              v-for="items in refundTypeList"
              :key="items.value"
              :label="items.name"
              :value="items.value"
            />
          </el-select>
          <el-input v-model="item.refundMoney" style="width: 200px" placeholder="输入可退费上限金额" />
          <el-button
            type="danger"
            icon="el-icon-minus"
            style="border-color: #fff;"
            @click="delRule(index)"
          />
        </div>
      </el-form-item>
      <el-button
        type="primary"
        icon="el-icon-plus"
        style="height: 36px;"
        @click="addRule()"
      />
    </el-form> -->
    <el-form :inline="true" class="demo-form-inline">
      <div class="title-top"><span />手动退费规则</div>
      <el-form-item label="可退款天数:">
        <el-input v-model="refund_day" style="width: 200px" placeholder="" />&nbsp;&nbsp;天
      </el-form-item>
      <el-form-item label="可实时退款距支付时间:">
        <el-input v-model="refund_min" style="width: 200px" placeholder="" />&nbsp;&nbsp;分钟后的订单
      </el-form-item>
    </el-form>
    <el-form :inline="true" class="demo-form-inline" style="text-align:center;">
      <el-button class="saveClick" type="primary" @click="saveClick">保 存</el-button>
    </el-form>
  </div>
</template>

<script>
import { refundcfgquery, refundcfgup } from '@/api/reconcliationConfig/payWaySetup/index'
export default {
  name: 'RefundRuleConfig',
  data() {
    return {
      // refundTypeList: [{ value: '1', name: '门诊' }, { value: '2', name: '住院' }, { value: '3', name: '体检' }],
      // refundTime: [],
      // refundRule: [],
      refund_day: '',
      refund_min: ''
    }
  },
  mounted() {
    this.onSearch()
  },
  methods: {
    onSearch() {
      // var params = {}
      // var that = this
      // params.page = that.page.currentPage // 当前页数
      // params.limit = that.page.pageSize // 每页展示条数
      // params.name = that.searchKey.directName
      // params.no = that.searchKey.no
      // params.status = that.searchKey.status
      const loading = this.$loading()
      refundcfgquery({})
        .then(res => {
          loading.close()
          this.refund_day = res.data.refund_day_limit
          this.refund_min = res.data.refund_min_limit
        })
        .catch(() => {
          loading.close()
        })
    },
    addTime() {
      if (this.refundTime.length >= 2) {
        this.$message({
          type: 'error',
          message: '日期不能大于2个'
        })
        return false
      } else {
        this.refundTime.push({ timeVal: '' })
      }
    },
    delTime(index) {
      if (this.refundTime.length <= 1) {
        this.$message({
          type: 'error',
          message: '最少不能低于一个'
        })
        return false
      } else {
        this.refundTime.splice(index, 1)
      }
    },
    addRule() {
      // if (this.refundRule.length >= 2) {
      //   this.$message({
      //     type: 'error',
      //     message: '日期不能大于2个'
      //   })
      //   return false
      // } else {
      //   this.refundRule.push({ timeVal: '' })
      // }
      this.refundRule.push({ refundType: '', refundMoney: '' })
    },
    delRule(index) {
      if (this.refundRule.length <= 1) {
        this.$message({
          type: 'error',
          message: '最少不能低于一个'
        })
        return false
      } else {
        this.refundRule.splice(index, 1)
      }
    },
    saveClick() {
      var params = {}
      params.daylimit = this.refund_day
      params.minlimit = this.refund_min
      const loading = this.$loading()
      refundcfgup(params)
        .then(res => {
          loading.close()
          this.$message({
            type: 'success',
            message: '修改成功'
          })
          this.onSearch()
        })
        .catch(() => {
          loading.close()
        })
    }
  }
}
</script>

<style lang="scss" scoped>
.payWaySetup {
  position: relative;
  width: 100%;
  height: calc(100vh - 84px);
  .demo-form-inline {
    .el-button--primary {
      background-color: #579ef8 !important;
      color: #fff !important;
    }
  }
  .btn {
    display: flex;
    align-items: center;
    justify-content: center;
  }
  .viewdetails {
    color: #1890ff;
    cursor: pointer;
  }
  .abnormal {
    color: #f65952;
    cursor: pointer;
  }
  .dialog-footer {
    text-align: center;
  }
}
.payWaySetup .el-dialog__header {
  text-align: center;
}
.icon-position{
    position: absolute;
    right: -16px;
    top: -18px;
}
.parent-position{
  position: relative;
  margin:0 20px;
}
.time-close{
  position: absolute;
  top: -7px;
  right: -7px;
}
.title-top{
  height: 60px;
  line-height: 60px;
  font-size: 20px;
  font-weight: 600;
  margin-left: 20px;
  display: flex;
  align-items: center;
}
.title-top span{
  display: inline-block;
  width: 4px;
  height: 24px;
  border-radius: 2px;
  background-color: #579ef8;
  margin-right: 8px;
}
.saveClick{
  width: 200px;
  margin-bottom: 50px;
  text-align: center;
}
</style>

